<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
			uni.getLocation({ //获取经纬度
				success: (res) => {
					console.log(res);
					let {longitude,latitude} = res
					// 让高德地图根据经纬度，下发城市信息
					let url = `https://restapi.amap.com/v3/geocode/regeo?key=8797592ffcb983c041b54da66bee871d&location=${longitude},${latitude}`
					uni.request({
						url,
						success: (info) => {
							console.log(info);
							let {province} = info.data.regeocode.addressComponent
							this.$store.commit('location/cityChangeMut',province)
						}
					})
				}
			})
			
			//初始化购物车
			try{
				let value = uni.getStorageSync('cartList')
				if(value){
					this.$store.commit('cart/cartInitMut',value)
				}
			}catch(e){
				console.log('本地存储购物车提取失败');
				//TODO handle the exception
			}
			
			// 初始化用户信息
			try{
				let value = uni.getStorageSync('userInfo')
				if(value){
					this.$store.commit('user/initUserInfoMut',value)
				}
			}catch(e){
				console.log('本地存储用户信息提取失败');
				//TODO handle the exception
			}
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "@/uni_modules/uview-ui/index.scss";
	@import url('@/colorui/icon.css');
	@import url('@/colorui/main.css');
	@import url('@/static/font/iconfont.css');
</style>
